﻿package com.lz.football.module.framework
{
	/**
	 * Sync Command (同步)同时执行
	 * @author lake
	 * 
	 */	
    public class SyncCommand extends RBCommand
	{
        private var _commands:Vector.<RBCommand>;
        private var _numCommandCompleted:int;

        public function SyncCommand(t:Number, ... _args)
		{
            super(t);
			var rbCmd:*;
            _numCommandCompleted = 0;
            _commands = new Vector.<RBCommand>();
            for each (rbCmd in _args) 
			{
                _commands.push(RBCommand(rbCmd));
            }
        }
        final override public function execute():void
		{
            var rbcCmd:RBCommand;
            for each (rbcCmd in _commands)
			{
				rbcCmd.callBack = oneCommandComplete;
				rbcCmd.start();
            }
        }
        private function oneCommandComplete():void
		{
            _numCommandCompleted++;
            if (_numCommandCompleted == _commands.length)
			{
                complete();
            }
        }
    }
}
